import Mock from 'mockjs'

import { getAllQuery } from './paramsDeal'
import { validateToken } from './tokenValidate'

const userList = (options) => {
    const params = getAllQuery(options.url)
    const loginTimeStamp = params.timeStamp
    const token = params.token
    const isTokenValid = validateToken(loginTimeStamp, token)

    // console.log('===user==token==isTokenValid', token, isTokenValid)
    if (!isTokenValid && token == 123456) {
        return {
            status: 401,
            message: 'token失效',
            data: {}
        }
    }

    return Mock.mock({
        status: 200,
        message: 'success',
        data: {
            total: 100,
            'rows|10': [
                {
                    id: '@guid',
                    name: '@cname',
                    'age|20-30': 23,
                    'job|1': ['前端工程师', '后端工程师', 'UI工程师', '需求工程师']
                }
            ]
        }
    })
}

export default {
    'get|/api/testStudy/service/userList': (options) => userList(options)
}
